/**
 * 
 */
package com.gosophia.orgManagement.action;

import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.organizationManagement.dto.OrganizationTreeDTO;
import com.gosophia.organizationManagement.ws.OrganizationManagementWebService;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 获取机构树形用action
 * @author wangxinbing,zhaoyan
 * @since  2010-12-31
 *  Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@Controller("GetOrganizationTreeAction")
@Scope("prototype")
public class GetOrganizationTreeAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    
    @Autowired
    private OrganizationManagementWebService organizationManagementWebService;
    @Autowired
    private UserManagementWebService userManagementWebService;
    //联系人
    private String contactJsonString ;
    private String organizationDTOs;
    
    public String execute()throws Exception{
        List<OrganizationTreeDTO> organizationDTOList = organizationManagementWebService.findRootOrganizations();
        organizationDTOs = JSONArray.fromObject(organizationDTOList).toString().replace("\"","\\\"" );
        
        List<UserInfoDTO> contactDTOs = userManagementWebService.findAllUserInfoHasAccount();
        if(contactDTOs!=null && contactDTOs.size()!=0){
            contactJsonString = JSONArray.fromObject(contactDTOs).toString().replace("\"", "\\\"");
        }
        return SUCCESS;
    }

    public String getOrganizationDTOs() {
        return organizationDTOs;
    }

    public void setOrganizationDTOs(String organizationDTOs) {
        this.organizationDTOs = organizationDTOs;
    }

    public String getContactJsonString() {
        return contactJsonString;
    }

    public void setContactJsonString(String contactJsonString) {
        this.contactJsonString = contactJsonString;
    }
    
}
